#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef char TypeData;
typedef struct TreeNode
{
	struct TreeNode* left;
	struct TreeNode* right;
	TypeData data;
}TN;

void PrevOrder(TN* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}

	else
	{
		printf("%c ", root->data);
		PrevOrder(root->left);
		PrevOrder(root->right);
	}
}

void InOrder(TN* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}

	else
	{
		InOrder(root->left);
		printf("%c ", root->data);
		InOrder(root->right);
	}
}

void PostOrder(TN* root)
{
	if (root == NULL)
	{
		printf("NULL ");
		return;
	}

	else
	{
		InOrder(root->left);
		InOrder(root->right);
		printf("%c ", root->data);
	}
}

int TreeSize(TN* root)
{
	return root == NULL ? 0 : TreeSize(root->left) + TreeSize(root->right) + 1;
}

int TreeLeafSize(TN* root)
{
	if (root == NULL)
	{
		return 0;
	}

	if (root->left == NULL && root->right == NULL)
	{
		return 1;
	}
	else
	{
		return TreeLeafSize(root->left) + TreeLeafSize(root->right);
	}
}

void Destory(TN* root)
{
	if (root == NULL)
	{
		return;
	}
	Destory(root->left);
	Destory(root->right);

	free(root);
	root == NULL;

}

int main()
{
	TN* A = (TN*)malloc(sizeof(TN));
	A->left = NULL;
	A->right = NULL;
	A->data = 'A';

	TN* B = (TN*)malloc(sizeof(TN));
	B->left = NULL;
	B->right = NULL;
	B->data = 'B';

	TN* C = (TN*)malloc(sizeof(TN));
	C->left = NULL;
	C->right = NULL;
	C->data = 'C';

	TN* D = (TN*)malloc(sizeof(TN));
	D->left = NULL;
	D->right = NULL;
	D->data = 'D';

	TN* E = (TN*)malloc(sizeof(TN));
	E->left = NULL;
	E->right = NULL;
	E->data = 'E';

	TN* F = (TN*)malloc(sizeof(TN));
	F->left = NULL;
	F->right = NULL;
	F->data = 'F';

	TN* G = (TN*)malloc(sizeof(TN));
	G->left = NULL;
	G->right = NULL;
	G->data = 'G';

	A->right = C;
	A->left = B;
	
	B->right = E;
	B->left = D;

	C->right = G;
	C->left = F;

	PrevOrder(A);
	printf("\n");
	InOrder(A);
	printf("\n");
	PostOrder(A);
	printf("\n");

	printf("%d\n",TreeSize(A));

	printf("%d\n",TreeLeafSize(A));
	
	

	return 0;
}